//
// Copyright (C) 2008 Jackson Harper (jackson@ximian.com)

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//

using System;
using System.Data;
using System.Configuration;
using System.Web;

using MySql.Data.MySqlClient;

namespace Grr.Model {

	[Serializable]
	public class DbEntity {

		private string name;

		public DbEntity ()
		{
		}

		protected DbEntity (string name)
		{
			this.name = name;
		}

		// The unique name in the DB
		public string Name {
			get { return name; }
			set { name = value; }
		}

		// A 'readable' uri name
		public virtual string UriName {
			get { return GrurrahString.ToUriString (name); }
		}

		public static MySqlConnection OpenReadConnection()
		{
			ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings["Read"];

			MySqlConnection res = new MySqlConnection(cs.ConnectionString);

			res.Open();
			return res;
		}

		public static MySqlConnection OpenReadWriteConnection()
		{
			ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings["ReadWrite"];

			MySqlConnection res = new MySqlConnection(cs.ConnectionString);

			res.Open();
			return res;
		}

		/*
		public static string MakeStringUriReady (string str)
		{
			string res = str.Replace(' ', '_');
			return res;
		}

		public static string MakeStringDbReady (string str)
		{
			string res = str.Replace('_', ' ');
			return res;
		}
		*/
	}
}

